//
//  JYRechargeController.m
//  JYFarm
//
//  Created by 花花 on 2017/10/11.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYRechargeController.h"
#import "JYRechargeCell.h"
#import "JYRechargeModel.h"
@interface JYRechargeController ()
    
@property(nonatomic)NSArray *titleArr;

@property(nonatomic)NSString *moneyStr;


@property(nonatomic)UIButton *selBtn;

@property(nonatomic)JYRechargeView *headerView;

@property(nonatomic)NSMutableArray *btnArr;
@end

@implementation JYRechargeController

- (void)viewDidLoad {
    [super viewDidLoad];


    [self setupUI];
    


}


- (void)setupUI{
  
    _btnArr = [NSMutableArray array];
    
    self.title = @"美点充值";
    self.titleArr = @[@"微信支付",@"支付宝支付",@"银行卡支付"];
    JYWeakSelf;
  self.headerView = [[JYRechargeView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 135)];
    __block NSString *moeny = _moneyStr;
    
    self.headerView.textFieldHandlerOnClick = ^(UIButton *btn,UITextField *textField){
        
        NSLog(@"大洋为:%@---%@",textField.text,moeny);
        if (![textField.text isEqualToString:moeny]) {

            NSLog(@"weakSelf:%zd",weakSelf.selBtn.selected);
            
            for (UIButton *button in weakSelf.btnArr) {
                button.selected = NO;
            }
        }
    
    };
    self.headerView.btnHandlerOnClick =  ^(UIButton *btn,NSMutableArray *arrAllBtn){
    
        moeny = btn.titleLabel.text;
        NSLog(@"%@",moeny);

        for (UIButton *button in arrAllBtn) {
            button.selected = button == btn ? YES : NO;
            if ( button.selected == YES) {
                weakSelf.selBtn = button;
                [weakSelf.btnArr addObject:weakSelf.selBtn];
            }
            NSLog(@"----%zd",button.selected);
        }
    };
    self.tableView.tableHeaderView  = self.headerView;
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];

    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, kBtnHeight+30)];
    UIButton *rechargeBtn  =  [UIButton jy_buttontitle:@"确认充值" titleColor:kfColor frame:CGRectMake(10, 30, Screen_Width-20, kBtnHeight) target:self action:@selector(rechargeOnClick) fontSize:17 bgImageName:@"login_button_background"];
    [footerView addSubview:rechargeBtn];
    self.tableView.tableFooterView = footerView;


    
}

- (void)rechargeOnClick{

    NSLog(@"充值");

//    NSString *money = [self.voucherArr[self.currentMoneyIndex.row] money];
    
//        NSLog(@"充值%@",money);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.titleArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    JYRechargeCell *cell = [JYRechargeCell cellWithTableView:tableView];
    cell.titleLabel.text = [self.titleArr safeObjectAtIndex:indexPath.row];
    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"%zd",indexPath.row);


}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 55)];
    headerView.backgroundColor = kBgColor;
    UILabel *label = [UILabel labelText:@"支付方式" fontSize:13 textColor:k3Color textAlignment:NSTextAlignmentCenter];
    label.backgroundColor = [UIColor whiteColor];
    label.frame = CGRectMake(0, 10, Screen_Width, 45);
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, headerView.height-1, Screen_Width, 1)];
    lineView.backgroundColor = kBgColor;
    [headerView addSubview:label];
    [headerView addSubview:lineView];
    return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 55;

}
@end
